﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class OverdueCostManagementService : IOverdueCostManagementService
    {
        private IOverdueCostManagementDal _overmanage;
        private IMapper _mapper;
        public OverdueCostManagementService(IOverdueCostManagementDal overmanage, IMapper mapper)
        {
            _overmanage = overmanage;
            _mapper = mapper;
        }

        public async Task<int> AddOverdueCostManagementAsync(int OverdueTime, int OverduePersonId, int OverdueStandardId)
        {
            return await _overmanage.AddAsync(new Overduecostmanagement 
            {
                OverdueTime = OverdueTime,
                OverduePersonId = OverduePersonId,
                OverdueStandardId = OverdueStandardId
            });
        }

        public async  Task<int> DeleteOverdueCostManagementAsync(int id)
        {
            var data = await _overmanage.QueryAsync(id);
            return data == null ? -1 : await _overmanage.DeleteAsync(data);
        }

        public async  Task<int> EditOverdueCostManagementAsync(int id, int OverdueTime, int OverduePersonId, int OverdueStandardId)
        {
            var data = await _overmanage.QueryAsync(id);
            if (data == null)
                return -1;
            data.OverdueTime = OverdueTime;
            data.OverduePersonId = OverduePersonId;
            data.OverdueStandardId = OverdueStandardId;
            return await _overmanage.EditAsync(data);
        }

        public async  Task<List<OverdueCostManagementDto>> QueryOverdueCostManagementAllAsync()
        {
            var data = await _overmanage.QueryAsync();
            return _mapper.Map<List<Overduecostmanagement>, List<OverdueCostManagementDto>>(data);
        }

        public async  Task<OverdueCostManagementDto> QueryOverdueCostManagementByIdAsync(int id)
        {
            var data = await _overmanage.QueryAsync(id);
            return _mapper.Map<Overduecostmanagement, OverdueCostManagementDto>(data);
        }
    }
}
